package cc.vv.btpartyjob.jobactivities.fragment

import android.content.Intent
import android.os.Bundle
import android.view.View
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.util.UserInfoManageUtil
import cc.vv.btpartyjob.jnimodule.server.UserRoleServer
import cc.vv.btpartyjob.jobactivities.R
import cc.vv.btpartyjob.jobactivities.activity.*
import cc.vv.btpartyjob.jobactivities.delegate.JobActivitiesMainFragmentDelegate
import cc.vv.btpartyjob.jobactivities.globle.IntentJobKey
import cc.vv.btpartyjob.jobactivities.inter.JobItemClickInterface
import cc.vv.btpartyjob.jobactivities.moudel.bean.JobBean
import cc.vv.btpartyjob.jobactivities.server.JobActivitiesServer
import cc.vv.mvp.binder.BaseDataBinder
import cc.vv.mvp.fragment.BaseFragmentMVP

/**
 * 工作活动Fragment界面
 * Created by Chen.qi on 2018/10/24.
 */
class JobActivitiesPageMainFragment : BaseFragmentMVP<JobActivitiesMainFragmentDelegate>(), JobItemClickInterface {

//    /**
//     * banner所有数据集合
//     */
//    private var bannerList: ArrayList<BannerBean>? = null
//    /**
//     * banner图片集合
//     */
//    private var bannerPic: ArrayList<String>? = null
//    /**
//     * banner图片集合
//     */
//    private var bannerTitle: ArrayList<String>? = null

    override fun initData() {
//        if (bannerList == null) {
//            bannerList = ArrayList()
//            bannerPic = ArrayList()
//            bannerTitle = ArrayList()
//            viewDelegate?.setData(JobActivitiesServer.getUnitHouse(), this)
//            viewDelegate?.setDataTypical(JobActivitiesServer.getTycipal(), this)
//        }

//        if (bannerList!!.size == 0) {
//            JniDataServer.getBannerList("0", 5, true)
//        }
    }

    override fun initView(bundle: Bundle?) {
        super.initView(bundle)
        viewDelegate?.setPicTop()
        viewDelegate?.setData(JobActivitiesServer.getUnitHouse(), this)
        viewDelegate?.setDataTypical(JobActivitiesServer.getTycipal(), this)

        if (UserRoleServer.getAreaRole() || UserInfoManageUtil.getUserInfo()?.yananRole == "RPOME") {
            viewDelegate?.showMingZhuShengHuoHui(true)
            viewDelegate?.showZuZhiLifeMeeting(true)
        }
        if (UserRoleServer.getAreaRole() || UserInfoManageUtil.getUserInfo()?.yananRole != "RMN") {
            viewDelegate?.showSanHuiYiKe((true))
            viewDelegate?.showZhiBuHuoDong(true)
        }

    }

    override fun bindEvenListener() {
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //社会主义核心价值观
            val intent = Intent(activity, HeXinJiaZhiActivity::class.java)
            startActivity(intent)

        }, R.id.oiv_fjm_top)


        viewDelegate?.setOnClickListener(View.OnClickListener {
            //民主生活会
            val intent = Intent(activity, MingZhuLifeMeetingActivity::class.java)
            intent.putExtra(IntentJobKey.INTENT_JOB_KEY_TITLE, "民主生活会")
            startActivity(intent)

        }, R.id.rl_fjm_mzLife)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //组织生活会
            val intent = Intent(activity, LifeWouldActivity::class.java)
            intent.putExtra(IntentJobKey.INTENT_JOB_KEY_TITLE, "组织生活会")
            startActivity(intent)
        }, R.id.rl_fjm_zuZhiLife)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //三会一课
            val intent = Intent(activity, SanHuiYiKeActivity::class.java)
            startActivity(intent)

        }, R.id.rl_fjm_sanHuiYiKe)
        viewDelegate?.setOnClickListener(View.OnClickListener {
            //支部活动
            val intent = Intent(activity, PartyBranchActivitiesActivity::class.java)
            intent.putExtra(IntentJobKey.INTENT_JOB_KEY_TITLE, "支部活动")
            startActivity(intent)
        }, R.id.rl_fjm_zhiBuHuoDong)
    }

    override fun getDelegateClass(): Class<JobActivitiesMainFragmentDelegate> {
        return JobActivitiesMainFragmentDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *>? {
        return null
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
//            is BannerResponseObj -> {
//                val data = obj.data ?: return
//                if (obj.data.records != null) {
//                    bannerPic!!.clear()
//                    bannerList!!.clear()
//                    bannerTitle!!.clear()
//                    for (i in 0 until obj.data.records.size) {
//                        val bannerBean = data.records[i]
//                        bannerPic!!.add(bannerBean?.cover!!)
//                        bannerTitle!!.add(bannerBean?.title!!)
//                        bannerList!!.add(bannerBean)
//                    }
//                    viewDelegate?.setBannerData(bannerPic!!, bannerTitle!!, ImgBannerView.ImgBannerClickInter { imgPath, position ->
//                        when (bannerList!![position].type) {
//                            0 -> {
//                                //传递id
////                                val intent = Intent(activity, WebDetailActivity::class.java)
////                                startActivity(intent)
//                                JniStartActivity.startIntentWebActivity(activity, H5UrlEnum.广告详情, bannerList?.get(position)?.id)
//                            }
//                            1 -> {
//                                //没有详情
//                            }
//                            2 -> {
//                                //外部链接
////                                val intent = Intent(activity, WebDetailActivity::class.java)
////                                intent.getStringExtra(IntentJniKey.INTENT_KEY_WEB_TITLE)
////                                intent.getStringExtra(IntentJniKey.INTENT_KEY_WEB_URL)
////                                startActivity(intent)
//                                JniStartActivity.startIntentWebActivity(activity, H5UrlEnum.广告详情.name, bannerList?.get(position)?.url)
//                            }
//                        }
//                    })
//                }
//            }
        }
    }

    override fun clickItem(operaObj: JobBean) {
        when (operaObj.title) {
            "宝塔头条" -> {
                val intent = Intent(activity, HeadingNewsActivity::class.java)
                intent.putExtra(IntentJobKey.INTENT_JOB_KEY_TITLE, operaObj.title)
                intent.putExtra("type", 0)
                startActivity(intent)
            }
            "街道头条" -> {
                val intent = Intent(activity, HeadingNewsActivity::class.java)
                intent.putExtra(IntentJobKey.INTENT_JOB_KEY_TITLE, operaObj.title)
                intent.putExtra("type", 1)
                startActivity(intent)
            }
            "社区头条" -> {
                val intent = Intent(activity, HeadingNewsActivity::class.java)
                intent.putExtra(IntentJobKey.INTENT_JOB_KEY_TITLE, operaObj.title)
                intent.putExtra("type", 2)
                startActivity(intent)
            }

            "网格头条" -> {
                val intent = Intent(activity, HeadingNewsActivity::class.java)
                intent.putExtra(IntentJobKey.INTENT_JOB_KEY_TITLE, operaObj.title)
                intent.putExtra("type", 3)
                startActivity(intent)
            }

            "农村党组织",
            "机关党组织",
            "社区党组织",
            "学校党组织",
            "非公党组织",
            "社会组织党组织",
            "国家企事业单位党组织" -> {
                val intent = Intent(activity, DemonstrationTypicalActivity::class.java)
                intent.putExtra(IntentJobKey.INTENT_JOB_KEY_TITLE, operaObj.title)
                startActivity(intent)
            }
        }
    }

}